<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class BaseRequest extends FormRequest
{
    protected $redirectAction = "BaseController@error";
    /**
     * 如果检测到错误了重定向到路由 BaseController@errors.
     *
     * @return string
     */
    protected function getRedirectUrl()
    {
        $url = $this->redirector->getUrlGenerator();

        if ($this->redirect) {
            return $url->to($this->redirect);
        } elseif ($this->redirectRoute) {
            return $url->route($this->redirectRoute);
        } elseif ($this->redirectAction) {
            // 验证后的没有通过验证的信息
            return $url->action($this->redirectAction,['errorMessage'=>$this->validator->messages()->getMessages()]);
        }

        return $url->previous();
    }
}
